<?php
	
	include_once "../../php/inc/defines.php";
	include_once "../../php/auth.php";
	include_once "../layout.php";
	include_once "../../php/treenode.php";
	include_once "../../php/formhandler.php";
	include_once "../../php/gestionnaireEtuMoy.php";
	include_once "../../php/sqlhandler.php";
	
	session_start();
	auth::secure(ETUDIANT);
	
	$tabs = array("Gestion des notes", "etu.php");
	layout::displayPageHeader($tabs, $tabs[0], TRUE, "treediv1");
	
?>
<div class="arborescence" id="treeViewDiv">
	<?php
		$tree1 = unserialize($_SESSION["etuTree"]);
		treenode::treeToHtml($tree1, ETUDIANT_1, 3);
	?>
</div>
<div class="content">
	<?php
		
		if(isset($_GET["nodetype"])) {
			if($_GET["nodetype"] == 2) { //si on est sur un noeud d'examen
				echo "<h1>Note de \"".$_GET["nodename"]."\"</h1>";
				$noteForm = new formhandler();
				$noteForm->getNoteForm($_SESSION["idEtud"], $_GET["id"]);
			}
			else if($_GET["nodetype"] == 1) { //si on est sur un noeud de module
				echo "<h1>Moyenne de \"".$_GET["nodename"]."\"</h1>";
				$g = new gestionnaireEtuMoy($_SESSION["idEtud"]);
				echo "<fieldset>";
				echo "<table class=\"ddeTable\">";
				echo $g->getTopLines();
				echo $g->getModuleNoteList($_GET["id"]);
				echo "</table></fieldset><br><br>";
				echo $g->getBottomLines("Moyenne sans les notes simul&eacute;es :", $g->getModuleMoy($_GET["id"], false), "Moyenne avec les notes simul&eacute;es :", $g->getModuleMoy($_GET["id"], true));
			}
			else if($_GET["nodetype"] == 0) {
				if(!isset($_GET["special"])) { //cas UE
					echo "<h1>Moyenne de \"".$_GET["nodename"]."\"</h1>";
					$g = new gestionnaireEtuMoy($_SESSION["idEtud"]);
					echo "<fieldset>";
					echo "<table class=\"ddeTable\">";
					echo $g->getTopLines();
					echo $g->getUESummary($_GET["id"]);
					echo "</table></fieldset><br><br>";
					echo $g->getBottomLines("Moyenne sans les notes simul&eacute;es :", $g->getUEMoy($_GET["id"], false), "Moyenne avec les notes simul&eacute;es :", $g->getUEMoy($_GET["id"], true));
					echo "<br><hr>";
					$sh = new sqlhandler();
					echo "<div class=\"bottomPageBar\">";
					echo "<form action=\"../../php/doueaction.php\" method=\"post\">";
					echo "<input class=\"left\" type=\"hidden\" name=\"id_ue\" value=\"".$_GET["id"]."\">";
					echo "<input class=\"left\" type=\"hidden\" name=\"id_etud\" value=\"".$_SESSION["idEtud"]."\">";
					echo "<input class=\"left\" type=\"checkbox\" id=\"capitalisee\" name=\"capitalisee\"";
					if(($moy = $sh->getMoyUECap($_SESSION["idEtud"], $_GET["id"])) != null)
						echo " checked";
					echo ">";
					echo "<label class=\"left\" for=\"capitalisee\">Cette UE est capitalis&eacute;e :</label>";
					echo "<input class=\"left uecap\" type=\"text\" name=\"moyenne_uecap\" placeholder=\"Saisir note\" value=\"";
					if($moy != null)
						echo $moy;
					echo "\">";
					echo "<input type=\"submit\" value=\"OK\">";
					echo "</form>";
					echo "</div>";
				}
				else { //cas parcours
					echo "<h1>Moyenne de \"".$_GET["nodename"]."\"</h1>";
					$g = new gestionnaireEtuMoy($_SESSION["idEtud"]);
					echo "<fieldset>";
					echo "<table class=\"ddeTable\">";
					echo $g->getTopLines();
					echo $g->getParcoursSummary($_GET["id"]);
					echo "</table></fieldset><br><br>";
					echo $g->getBottomLines("Moyenne sans les notes simul&eacute;es :", $g->getParcoursMoy($_GET["id"], false), "Moyenne avec les notes simul&eacute;es :", $g->getParcoursMoy($_GET["id"], true));
				}
			}
		}
		else { //cas etudiant global
			echo "<h1>Moyenne de ".$_SESSION["login"]."</h1>";
			$g = new gestionnaireEtuMoy($_SESSION["idEtud"]);
			echo "<fieldset>";
			echo "<table class=\"ddeTable\">";
			echo $g->getTopLines();
			echo $g->getEtuSummary();
			echo "</table></fieldset><br><br>";
			echo $g->getBottomLines("Moyenne sans les notes simul&eacute;es :", $g->getEtuMoy(false), "Moyenne avec les notes simul&eacute;es :", $g->getEtuMoy(true));
		}
		
	?>
</div>
<?php
	
	layout::displayPageFooter();
	
?>
